package com.cxg.fairy.ec.detail;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ListView;

import com.cxg.fairy.delegates.LatteDelegate;
import com.cxg.fairy.net.RestClient;
import com.cxg.fairy.net.callback.ISuccess;
import com.cxg.fairy.ui.recycler.MultipleItemEntity;
import com.cxg.fairy.util.log.LatteLogger;
import com.diabin.latte.ec.R;
import com.diabin.latte.ec.R2;

import java.util.List;

import butterknife.BindView;

/**
 * Created by gabrielsung on 2018/4/6 0006.
 */

public class StandardDelegate extends LatteDelegate implements ISuccess{

    List<MultipleItemEntity> data = null;

    @BindView(R2.id.lvc_goods_detail_standard)
    ListView standardListView = null;

    @Override
    public Object setLayout() {
        return R.layout.delegate_goods_detail_standard;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        initStandardEntity();
    }

    private void initStandardEntity() {
        RestClient.builder()
                .url("getGoodsSpec")
                .params("sku_id", 100)
                .success(this)
                .build()
                .post();
    }


    @Override
    public void onSuccess(String response) {
        data = new StandardDataConverter().setJsonData(response).convert();
        final StandardAdapter standardAdapter = new StandardAdapter(getContext(), R.layout.item_goods_detail_standard, data);
        standardListView.setAdapter(standardAdapter);
    }
}
